﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:view="clr-namespace:GurLoader.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    xmlns:glView="clr-namespace:GurLoader.View"
    x:Class="GurLoader.View.MainWindow"
    ResizeMode="NoResize" SizeToContent="WidthAndHeight"
    Title="{Binding CommandProgress.Command, Converter={glView:TaskCommandDescriptionConverter}}"  
    MinWidth="550" MaxHeight="500"
    Icon="/Resources/GurLoader.ico"
    d:DesignHeight="435">
    <Window.Resources>
        <glView:AutoElipseTextConverter x:Key="ElipseTextConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <!-- MAIN PROGRESS BAR -->
            <RowDefinition Height="*" />
            <!-- EXPANDER -->
            <RowDefinition Height="Auto" />
            <!-- CANCEL AND STATUS MESSAGE -->
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <ProgressBar
                HorizontalAlignment="Stretch" Height="30" Margin="5,5,5,5"
                Value="{Binding CommandProgress.TotalProgressPercentage}"
                Grid.Column="0"
                Minimum="-1"
                view:ProgressBarHelper.StopAnimationOnCompletion="True"
                VerticalAlignment="Top" />
                <TextBlock Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Setter Property="Text" Value=""/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding CommandProgress.IsCancelled}" Value="True">
                                    <Setter Property="Text" Value="Cancelled"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            <Button Grid.Column="1" Command="{Binding ClipboardCopyItemLinkCommand}" CommandParameter="{Binding CommandProgress}">
                <Button.Template>
                    <ControlTemplate>
                        <Image Source="/Resources/clipboard-sign-icon.png"/>
                    </ControlTemplate>
                </Button.Template>
            </Button>
            <Button Grid.Column="2" Command="{Binding BrowserOpenItemLinkCommand}" CommandParameter="{Binding CommandProgress}" >
                <Button.Template>
                    <ControlTemplate>
                        <Image Source="/Resources/globe32.png"/>
                    </ControlTemplate>
                </Button.Template>
            </Button>
        </Grid>
        
        <Expander Grid.Row="1" HorizontalAlignment="Stretch" IsExpanded="False" >
                <ListBox ItemsSource="{Binding CommandProgress.Children}" 
                         HorizontalAlignment="Stretch" 
                         HorizontalContentAlignment="Stretch"
                         VerticalAlignment="Stretch" 
                         MaxHeight="300"
                         x:Name="ChildTasks">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <StackPanel>
                                        <ContentPresenter/>
                                        <Separator/>
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
                    
                <ListBox.ItemTemplate>
                        <DataTemplate>
                        <!-- MaxHeight="30"-->
                            <Grid Margin="8,4,4,4" HorizontalAlignment="Stretch" >
                               <Grid.ColumnDefinitions>
                                   <ColumnDefinition Width="*"/>
                                   <ColumnDefinition Width="150"/>
                                   <ColumnDefinition Width="Auto"/>
                                   <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                
                                <!-- <TextBlock Grid.Column="0" Text="{Binding Status}"/>-->
                                
                                <Grid Grid.Column="0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>

                                    <TextBlock Grid.Column="0" Text="{Binding Status}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding ContentDescription, Converter={StaticResource ElipseTextConverter}}"/>
                                </Grid>
                                
                                <ProgressBar Grid.Column="1" Minimum="-1" Value="{Binding ProgressPercentage}" view:ProgressBarHelper.StopAnimationOnCompletion="True"/>
                                <TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="Text" Value=""/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsCancelled}" Value="True">
                                                    <Setter Property="Text" Value="Cancelled"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding IsComplete}" Value="True">
                                                    <Setter Property="Visibility" Value="Hidden"/>
                                                </DataTrigger>
                                        </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            <Button Grid.Column="2" Command="{Binding ElementName=ChildTasks, Path=DataContext.ClipboardCopyItemLinkCommand}" CommandParameter="{Binding}">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Image Source="/Resources/clipboard-sign-icon.png"/>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                                <Button Grid.Column="3" Command="{Binding ElementName=ChildTasks, Path=DataContext.BrowserOpenItemLinkCommand}" CommandParameter="{Binding}">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Image Source="/Resources/globe32.png"/>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    
                </ListBox>
        </Expander>

        <Grid Grid.Row="2" Margin="5,5,5,5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="Status:" Grid.Column="0" Margin="0,0,10,0" />
            <TextBlock HorizontalAlignment="Stretch" Text="{Binding CommandProgress.Status}" Grid.Column="1" />
            <Button Content="Cancel" 
                    Command="{Binding RequestCancelCommand}" 
                    Grid.Column="2" />

        </Grid>

    </Grid>
</Window>